/**
 * api数据获取
 * @param apiId 模型id
 * @param apiType WIDZOM：智云；BUNCHES：灵珑
 * @param params 查询条件
 * @param extraParams lostAbility 第一位表示1：缺失分页能力，第二位 表示缺失排序能力。
 * @return Promise<ResponseResult>
 */
function main(pageId, param) {
    return new Promise((resolve, reject) => {
        console.log(pageId, param)
        api.API_DATA_EXECUTE("8e0956b2-1c53-407f-a109-4725610963cb", "BUNCHES", param, { lostAbility: "01" })
            .then(res => {
                resolve(res);
            }).catch(() => {
                reject();
            })
    })
}


function main(pageId, param) {
    return new Promise((resolve, reject) => {
        console.log(pageId, param);
        // 使用数据模型来代替默认查询逻辑，dataModeId为数据模型ID
        const dataModeId = "3a2ebb83-1cb2-4af6-8a51-e95e69a05206";
        api.DATA_EXECUTOR().executeDataModelForList(dataModeId, param)
            .then(res => {
                resolve(res);
            }).catch(() => {
                reject();
            })
    })
}


/**
 * api数据获取
 * @param apiId 模型id
 * @param apiType WIDZOM：智云；BUNCHES：灵珑
 * @param params 查询条件
 * @param extraParams lostAbility 第一位表示1：缺失分页能力，第二位 表示缺失排序能力。
 * @return Promise<ResponseResult>
 */
function main(pageId, param) {
    return new Promise((resolve, reject) => {
        console.log(pageId, param)
        api.API_DATA_EXECUTE("8e0956b2-1c53-407f-a109-4725610963cb", "BUNCHES", param, { lostAbility: "01" })
            .then(res => {
                resolve(res);
            }).catch(() => {
                reject();
            })
    })
}


function main(pageId, param) {
    return new Promise((resolve, reject) => {
        console.log(pageId, param);
        // 使用数据模型来代替默认查询逻辑，dataModeId为数据模型ID
        const dataModeId = "f8dfa394-d8c4-4a3d-9a5f-18584ad3c4f5";
        api.DATA_EXECUTOR().executeApiModelForList(dataModeId, "BUNCHES", param, { lostAbility: "01" })
            .then(res => {
                resolve(res);
            }).catch(() => {
                reject();
            })
    })
}

function main(param) {
    let self = this;
    const currentDate = new Date();
    const startTime = currentDate.getFullYear() + '-' + (currentDate.getMonth() + 1) + '-01 00:00:00';
    const endTime = currentDate.getFullYear() + '-' + (currentDate.getMonth() + 1) + '-' + currentDate.getDate() + ' 23:59:59';
    if (param) {
        startTime = param.start.format("YYYY-MM-DD 00:00:00");
        endTime = param.end.format("YYYY-MM-DD 23:59:59");
    }
    //调用ddcat数据模型
    api.DATA_SOURCE_EXECUTE('eaa4f91a-0f1e-4726-a131-3834c682c69f', 'ddcat', [
        {
            name: 'unitId',
            text: '开始时间',
            type: 'QueryString',
            valueContent: unitId,
            valueType: null
        },
        {
            name: 'endTime',
            text: '截止时间',
            type: 'QueryString',
            valueContent: endTime,
            valueType: null
        }
    ], [], '').then(res => {
        if (res && !res.hasError && res.result) {
            let item1 = res.result[0];
            let item2 = res.result[1];
            let item3 = res.result[2];
            let item4 = res.result[3];
            let list1 = [
                {
                    "text": "自然灾害",
                    "value": item1.totalNum,
                    "unit": ""
                },
                {
                    "text": "处置中",
                    "value": item1.disposeNum,
                    "unit": ""
                },
                {
                    "text": "已结案",
                    "value": item1.finishNum,
                    "unit": ""
                },
                {
                    "text": "办结率",
                    "value": item1.finishRate,
                    "unit": "%"
                }
            ];
            let list2 = [
                {
                    "text": "事故灾难",
                    "value": item2.totalNum,
                    "unit": ""
                },
                {
                    "text": "处置中",
                    "value": item2.disposeNum,
                    "unit": ""
                },
                {
                    "text": "已结案",
                    "value": item2.finishNum,
                    "unit": ""
                },
                {
                    "text": "办结率",
                    "value": item2.finishRate,
                    "unit": "%"
                }
            ];
            let list3 = [
                {
                    "text": "公共卫生事件",
                    "value": item3.totalNum,
                    "unit": ""
                },
                {
                    "text": "处置中",
                    "value": item3.disposeNum,
                    "unit": ""
                },
                {
                    "text": "已结案",
                    "value": item3.finishNum,
                    "unit": ""
                },
                {
                    "text": "办结率",
                    "value": item3.finishRate,
                    "unit": "%"
                }
            ];
            let list4 = [
                {
                    "text": "社会安全事件",
                    "value": item4.totalNum,
                    "unit": ""
                },
                {
                    "text": "处置中",
                    "value": item4.disposeNum,
                    "unit": ""
                },
                {
                    "text": "已结案",
                    "value": item4.finishNum,
                    "unit": ""
                },
                {
                    "text": "办结率",
                    "value": item4.finishRate,
                    "unit": "%"
                }
            ];
            self.$$('csdn_form_data_overview_35fgii').data.props.dataSource.options = list1;
            self.$$('csdn_form_data_overview_uxfz7').data.props.dataSource.options = list2;
            self.$$('csdn_form_data_overview_3ykc48').data.props.dataSource.options = list3;
            self.$$('csdn_form_data_overview_gu2j2h').data.props.dataSource.options = list4;
        }
    }).catch(err => { });
}
